<?php
defined('IN_TS') or die('Access Denied.');  

class duty extends tsApp{
	
	//构造函数
	public function __construct($db){

		parent::__construct($db);


	}
	
	//获取一条服务
	public function getOneDuty($dutyid){
		
		$strDuty = $this->find('duty',array(
			'dutyid'=>$dutyid,
		));

		if($strDuty){
			$strDuty['user']=aac('user')->getOneUser($strDuty['userid']);
			$arr= $this->find('duty_cate',array('cateid'=>$strDuty['cateid']),'catename');
			$strDuty['cate']=$arr['catename'];
			$strDuty['group'] = aac('group')->getOneGroup($strDuty['groupid']);
			$strDuty['job'] = delempty($strDuty['job']);
		}


		return $strDuty;
		
	}

	public function getSignPackage(){

		require_once "plugins/pubs/weixin/jssdk.php";
		$jssdk = new JSSDK("wx2ef8a11062078826", "16863a6f1c9e1a438b5c05922681c3d3");
		$signPackage = $jssdk->GetSignPackage();
		return $signPackage;

	}

	/**
	 * 获取服务类型
	 *
	 * @param integer $cateid
	 * @return string
	 */
	public function getDutyCate($cateid)
	{
		$dutyCate = $this->find('duty_cate',array(
			'cateid'=>$cateid,
		));
		return $dutyCate ? $dutyCate['catename'] : '';
	}

	/**
	 * 获取所有服务类型
	 *
	 * @return array
	 */
	function getDutyCates() 
	{
		$data = $this->findAll('duty_cate');
		if ($data) {
			$data = array_use_field_index($data, "cateid");
		}
		return $data;
	}

	/**
	 * 获取服务时间
	 *
	 * @param integer $beginTime
	 * @param integer $endTime
	 * @return string
	 */
	public function duration($beginTime, $endTime = 0)
	{
		$duration = "";
		if ($endTime == 0) {
			$duration = date('Y-m-d',$beginTime);
		} else {
			$duration = date('Y-m-d H:i',$beginTime)."至".date('H:i',$endTime);
		}
		return $duration;
	}
}